package com.itcast.donkey.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.itcast.donkey.R;
import com.itcast.donkey.modles.AttackModles;
import com.squareup.picasso.Picasso;

/**
 * Created by lanouhn on 16/8/24.
 */
public class GridViewAttackAdapter extends BaseAdapter {

    private Context context;
    private AttackModles modles;
    private ViewHolder holder;

    public GridViewAttackAdapter(Context context, AttackModles modles) {
        this.context = context;
        this.modles = modles;
    }

    @Override
    public int getCount() {
        return modles.getDestinations().size();
    }

    @Override
    public Object getItem(int position) {
        return modles.getDestinations().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        holder = new ViewHolder();
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_attack_guide, null);
            holder.tv_name = (TextView) convertView.findViewById(R.id.tv_attack_country);
            holder.tv_english = (TextView) convertView.findViewById(R.id.tv_attack_english);
            holder.tv_poi_count = (TextView) convertView.findViewById(R.id.tv_attack_poi_count);
            holder.iv_background = (ImageView) convertView.findViewById(R.id.iv_attack_guide);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tv_name.setText(modles.getDestinations().get(position).getName_zh_cn());
        holder.tv_english.setText(modles.getDestinations().get(position).getName_en());
        holder.tv_poi_count.setText(modles.getDestinations().get(position).getPoi_count() + "旅行地");
        holder.iv_background.setScaleType(ImageView.ScaleType.FIT_XY);
        Picasso.with(context).load(modles.getDestinations().get(position).getImage_url()).into(holder.iv_background);
        return convertView;
    }

    public class ViewHolder {

        private TextView tv_name, tv_english, tv_poi_count;
        private ImageView iv_background;
    }
}
